package com.bjwl.web.contrlller.admin;

import com.bjwl.pojo.BranchStore;
import com.bjwl.pojo.Card;
import com.bjwl.pojo.CardDenomination;
import com.bjwl.pojo.Invoice;
import com.bjwl.pojo.vo.CardQueryVo;
import com.bjwl.pojo.vo.QueryInvoiceVo;
import com.bjwl.service.BranchStoreService;
import com.bjwl.service.InvoiceService;
import com.bjwl.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.util.List;

/**
 * @Author: dzx
 * @Date:Create：in 2020/5/13 8:56
 * @Description:
 * @Modified By：
 * @Version: 1.0
 */
@Controller
@RequestMapping("/admin")
public class InvoiceController {

    @Autowired
    private InvoiceService invoiceService;

    @Autowired
    private BranchStoreService branchStoreService;

    @RequestMapping("/findAllInvoice")
    public String findAllInvoice(QueryInvoiceVo vo, Model model){
        List<BranchStore> list = branchStoreService.getBranchStoreId();
        PageBean<Invoice> pageBean = invoiceService.findAllInvoice(vo);
        model.addAttribute("pageBean",pageBean);
        model.addAttribute("bsList",list);
        return "main_oa/bill-list";
    }

    @RequestMapping("/showAdd")
    public String showAdd(Model model){
        List<BranchStore> list = branchStoreService.getBranchStoreId();
        model.addAttribute("bsList",list);
        return "main_oa/bill-add";
    }

    @RequestMapping("/addInvoice")
    public @ResponseBody
    boolean addInvoice(@RequestBody Invoice vo){
        return invoiceService.addInvoice(vo);
    }

    @RequestMapping("/editSInvoice")
    public String editSInvoice(Integer id, Model model) throws ParseException {
        Invoice invoice = invoiceService.editS(id);
        List<BranchStore> list = branchStoreService.getBranchStoreId();
        model.addAttribute("bsList",list);
        model.addAttribute("invoice",invoice);
        return "main_oa/bill-edit";
    }

    @RequestMapping("/editEInvoice")
    public @ResponseBody
    boolean editEInvoice(@RequestBody Invoice invoice){
        return invoiceService.updateInvoice(invoice);
    }

    @RequestMapping("/deleteInvoice")
    public @ResponseBody
    boolean deleteInvoice(@RequestBody Integer id){
        return invoiceService.deleteInvoice(id);
    }

}
